from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from unittest import TestCase


class TestLogin(TestCase):
    def testUser1(self):
        expect = "个人理财系统"
        username = "lisi"
        password = "123456"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90")
        ele1 = driver.find_element(By.XPATH, "//*[@id='username']")
        ele1.send_keys(username)
        ele2 = driver.find_element(By.ID, 'password')
        ele2.send_keys(password)
        ele3 = driver.find_element(By.ID, 'login_btn')
        ele3.click()
        time.sleep(2)
        result = driver.title
        if expect != result:
            print("不通过")
            driver.save_screenshot(r"C:\Users\Administrator\PycharmProjects\pythonProject\TEST"
                                   r"\测试截图\lisi_123456_login.png")
        else:
            print("用例通过！")
        driver.quit()
        self.assertEqual(result, expect)

    def testRoot1(self):
        expect = "后台管理系统"
        username = "admin"
        password = "123456"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90")
        ele1 = driver.find_element(By.XPATH, "//*[@id='username']")
        ele1.send_keys(username)
        ele2 = driver.find_element(By.ID, 'password')
        ele2.send_keys(password)
        ele3 = driver.find_element(By.ID, 'login_btn')
        ele3.click()
        time.sleep(2)
        result = driver.title
        if expect != result:
            print("不通过")
            driver.save_screenshot(r"C:\Users\Administrator\PycharmProjects\pythonProject\TEST"
                                   r"\测试截图\admin_123456_login.png")
        else:
            print("用例通过！")
        driver.quit()
        self.assertEqual(result, expect)

    def testUser2(self):
        expect = "个人理财系统"
        username = "lisi3"
        password = "123456"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90")
        ele1 = driver.find_element(By.XPATH, "//*[@id='username']")
        ele1.send_keys(username)
        ele2 = driver.find_element(By.ID, 'password')
        ele2.send_keys(password)
        ele3 = driver.find_element(By.ID, 'login_btn')
        ele3.click()
        time.sleep(2)
        result = driver.title
        if expect != result:
            print("不通过")
            driver.save_screenshot(r"C:\Users\Administrator\PycharmProjects\pythonProject\TEST"
                                   r"\测试截图\lisi3_123456_login.png")
        else:
            print("用例通过！")
        driver.quit()
        self.assertEqual(result, expect)

    def testUser3(self):
        expect = "个人理财系统"
        username = "lisi"
        password = "123457"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90")
        ele1 = driver.find_element(By.XPATH, "//*[@id='username']")
        ele1.send_keys(username)
        ele2 = driver.find_element(By.ID, 'password')
        ele2.send_keys(password)
        ele3 = driver.find_element(By.ID, 'login_btn')
        ele3.click()
        time.sleep(2)
        result = driver.title
        if expect != result:
            print("不通过")
            driver.save_screenshot(r"C:\Users\Administrator\PycharmProjects\pythonProject\TEST"
                                   r"\测试截图\lisi_123457_login.png")
        else:
            print("用例通过！")
        driver.quit()
        self.assertEqual(result, expect)

    def testRoot2(self):
        expect = "后台管理系统"
        username = "admin1"
        password = "123456"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90")
        ele1 = driver.find_element(By.XPATH, "//*[@id='username']")
        ele1.send_keys(username)
        ele2 = driver.find_element(By.ID, 'password')
        ele2.send_keys(password)
        ele3 = driver.find_element(By.ID, 'login_btn')
        ele3.click()
        time.sleep(2)
        result = driver.title
        if expect != result:
            print("不通过")
            driver.save_screenshot(r"C:\Users\Administrator\PycharmProjects\pythonProject\TEST"
                                   r"\测试截图\admin1_123456_login.png")
        else:
            print("用例通过！")
        driver.quit()
        self.assertEqual(result, expect)

    def testRoot3(self):
        expect = "后台管理系统"
        username = "admin"
        password = "123457"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90")
        ele1 = driver.find_element(By.XPATH, "//*[@id='username']")
        ele1.send_keys(username)
        ele2 = driver.find_element(By.ID, 'password')
        ele2.send_keys(password)
        ele3 = driver.find_element(By.ID, 'login_btn')
        ele3.click()
        time.sleep(2)
        result = driver.title
        if expect != result:
            print("不通过")
            driver.save_screenshot(r"C:\Users\Administrator\PycharmProjects\pythonProject\TEST"
                                   r"\测试截图\admin_123457_login.png")
        else:
            print("用例通过！")
        driver.quit()
        self.assertEqual(result, expect)
